package org.eiahe.hr.attendance.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import lombok.RequiredArgsConstructor;
import org.ehe.common.core.BaseController;
import org.ehe.common.core.domain.R;
import org.ehe.common.excel.utils.ExcelUtil;
import org.ehe.common.log.annotation.Log;
import org.ehe.common.log.enums.BusinessType;
import org.ehe.common.mybatis.core.page.PageQuery;
import org.ehe.common.mybatis.core.page.TableDataInfo;
import org.eiahe.hr.attendance.domain.bo.EmployeeAttendanceSummaryBo;
import org.eiahe.hr.attendance.domain.bo.MonthlyAttendanceStatBo;
import org.eiahe.hr.attendance.domain.vo.EmployeeAttendanceSummaryVo;
import org.eiahe.hr.attendance.domain.vo.MonthlyAttendanceStatVo;
import org.eiahe.hr.attendance.service.IEmployeeAttendanceSummaryService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import jakarta.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 员工考勤汇总Controller
 *
 * @author zhangnn
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/attendance/summary")
public class EmployeeAttendanceSummaryController extends BaseController {

    private final IEmployeeAttendanceSummaryService employeeAttendanceSummaryService;

    /**
     * 查询员工月度考勤汇总
     */
    @SaCheckPermission("attendance:summary:query")
    @GetMapping("/monthly")
    public R<EmployeeAttendanceSummaryVo> getMonthlySummary(
            @RequestParam String employeeNo,
            @RequestParam Integer year,
            @RequestParam Integer month) {
        EmployeeAttendanceSummaryVo summary = employeeAttendanceSummaryService.getMonthlySummary(employeeNo, year,
                month);
        return R.ok(summary);
    }

    /**
     * 查询员工年度考勤汇总
     */
    @SaCheckPermission("attendance:summary:query")
    @GetMapping("/annual")
    public R<EmployeeAttendanceSummaryVo> getAnnualSummary(
            @RequestParam String employeeNo,
            @RequestParam Integer year) {
        EmployeeAttendanceSummaryVo summary = employeeAttendanceSummaryService.getAnnualSummary(employeeNo, year);
        return R.ok(summary);
    }

    /**
     * 查询员工考勤汇总列表
     */
    @SaCheckPermission("attendance:summary:list")
    @GetMapping("/list")
    public R<List<EmployeeAttendanceSummaryVo>> listSummary(
            @RequestParam String employeeNo,
            @RequestParam Integer year,
            @RequestParam(required = false) Integer month) {
        List<EmployeeAttendanceSummaryVo> list = employeeAttendanceSummaryService.listSummary(employeeNo, year, month);
        return R.ok(list);
    }

    /**
     * 分页查询员工考勤汇总列表
     */
    @SaCheckPermission("attendance:summary:list")
    @GetMapping("/page")
    public TableDataInfo<EmployeeAttendanceSummaryVo> listSummaryPage(EmployeeAttendanceSummaryBo bo,
            PageQuery pageQuery) {
        return employeeAttendanceSummaryService.listSummaryPage(bo.getEmployeeNo(), bo.getYear(), bo.getMonth(),
                pageQuery);
    }

    /**
     * 导出员工考勤汇总列表
     */
    @SaCheckPermission("attendance:summary:export")
    @Log(title = "员工考勤汇总", linkType = "attendance", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(EmployeeAttendanceSummaryBo bo,
            HttpServletResponse response) {
        List<EmployeeAttendanceSummaryVo> list = employeeAttendanceSummaryService.listSummary(bo.getEmployeeNo(), bo.getYear(), bo.getMonth());
        ExcelUtil.exportExcel(list, "员工考勤汇总", EmployeeAttendanceSummaryVo.class, response);
    }
}
